﻿/*!
 *  @brief     语言管理
 *  @details
 *  @author    wey
 *  @version   1.0
 *  @date      2018.09.15
 *  @warning
 *  @copyright NanJing RenGu.
 *  @note
 */
#ifndef SYSTEMLANGUAGE_H
#define SYSTEMLANGUAGE_H

#include "common_global.h"

#include <QObject>
#include <QList>

class QAction;

namespace Common{

class COMMONSHARED_EXPORT Language
{
public:
    Language(QString fileName,QString countryCode);

    /**
     * @brief getName
     * @return
     */
    QString getName()const{return this->name;}

    /**
     * @brief getFileName
     * @return
     */
    QString getFileName()const{return this->fileName;}

    /**
     * @brief setSelected
     * @param flag
     */
    void setSelected(bool flag){this->selected = flag;}

    /**
     * @brief isSelected
     * @return
     */
    bool isSelected()const{return this->selected;}

    /**
     * @brief setAction
     * @param act
     */
    void setAction(QAction * act){this->action = act;}

    /**
     * @brief getAction
     * @return
     */
    QAction * getAction(){return action;}

private:
    /**
     * @brief switchName 切换名称
     * @param code
     */
    void switchName(QString code);

private:
    QString name;           /*!< Action显示语言名称 */
    QString fileName;       /*!< 翻译文件名(带后缀) */
    bool selected;          /*!< 是否被选中显示 */
    QAction * action;
};

typedef QList<Language *> LanguagePtrList;          // 语言列表


class LanguageHandlerPrivate;
class COMMONSHARED_EXPORT LanguageHandler : public QObject
{
    Q_OBJECT
    Q_DECLARE_PRIVATE(LanguageHandler)
public:
    explicit LanguageHandler();
    ~LanguageHandler();

    /*!
     * @brief 从指定目录中加载翻译文件
     * @param[in] filePath 指定的存放路径(文件夹路径)
     */
    void loadTranslator(QString filePath);

    /*!
     * @brief 切换至对应的翻译文件
     * @param[in] fileName 文件名
     * @return 是否切换成功
     */
    bool switchLanguage(QString fileName);

    /**
     * @brief languages 获取语言列表
     * @return
     */
    LanguagePtrList languages();

    /**
     * @brief findLan 查看语言是否存在
     * @param fileName
     * @return
     */
    Language * findLan(QString fileName);

private:
    LanguageHandlerPrivate * d_ptr;                  // 定义了一个指针d_ptr指向私有实现类
};

} //namespace Base

#endif // SYSTEMLANGUAGE_H
